package com.mmall.concurrency.tujie.chapter3;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 孙许
 * @date 2018-05-20
 * @description
 */
@Slf4j
public class TalkThread extends Thread {
    private final RequestQueue input;
    private final RequestQueue output;

    public TalkThread(RequestQueue input, RequestQueue output, String name) {
        super(name);
        this.input = input;
        this.output = output;
    }

    @Override
    public void run() {
        log.info(Thread.currentThread().getName() + ":Begin");
        for (int i = 0; i < 20; i++) {
            Request request1 = input.getRequest();
            log.info(Thread.currentThread().getName() + " gets " + request1);

            Request request2 = new Request(request1.getName() + "!");
            log.info(Thread.currentThread().getName() + " puts " + request2);
            output.putRequest(request2);
        }
        log.info(Thread.currentThread().getName() + ":End");
    }
}
